﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Exceptions;
using PT.ThueXe;
using System.Xml;
using System.Data;
using Telerik.Web.UI;

namespace PT.MuaBanXe
{
    partial class EditMuaBanXe : PortalModuleBase
    {

        #region Private Members
        public MuaBanXeController _objCarController;
        public string xmlSpecification = @"<root>
                <thongtincoban hangchetao='{0}' doixe='{1}' model='{2}' namsanxuat='{3}' xuatxu='{4}' tinhtrang='{5}' sokm='{6}' dongxe='{7}' ngoaithat='{8}' noithat='{9}' socua='{10}' sochongoi='{11}' />
                <nhienlieu hethongnap='{12}' nhienlieu='{13}' />
                <hopsochuyendong hopso='{14}' dandong='{15}' muctieuthu='{16}' />
                <tuikhiantoan tuikhinguoilai='{17}' tuikhitruoc='{18}' tuikhisau='{19}' tuikhihaiben='{20}' tuikhitreophiatren='{21}'/>
                <phanhdieukhien chongbocungphanh='{22}' phanbolucphanhdientu='{23}' trolucphanhkhancap='{24}' tudongcanbangdientu='{25}' dieukhienhanhtrinh='{26}' hotrobaolui='{27}' hethongkiemsoattruot='{28}'/>
                <khoachongtrom chotcuaantoan='{29}' khoacuatudong='{30}' khoacuadieukhientuxa='{31}' khoadongco='{32}' hethongbaotromngoaivi='{33}'/>
                <thongsokhac densuongmu='{34}' dencanhbaotatdayantoan='{35}' denphanhphuthu3lapcao='{36}'/>
                <tiennghi thietbidinhvi='{37}' cuasonoc='{38}' kinhchinhdien='{39}' taylaitroluc='{40}' ghe='{41}' dieuhoatruoc='{42}' dieuhoasau='{43}' hotroxetudong='{44}' xaykinhsau='{45}' quatkinhsau='{46}' kinhmau='{47}' manhinhlcd='{48}' thietbigiaitri='{49}' thietbikhac='{50}'/>
                <kichthuoctrongluong dairongcao='{51}' daicoso='{52}' rongcoso='{53}' trongluong='{54}' dungtich='{55}' />
                <dongco dongco='{56}' kieudongco='{57}' dungtichxilanh='{58}' />
                <phanhxoclop phanh='{59}' giamxoc='{60}' lopxe='{61}' vanhmamxe='{62}' />
        </root>";

        public string xmlContact = @"<root>
            <info person='{0}' address='{1}' phone='{2}' />
        </root>";

        #endregion

        #region Public Methods

        public MuaBanXeController objCarController
        {
            get
            {
                if (this._objCarController == null)
                {
                    this._objCarController = new MuaBanXeController();
                }
                return this._objCarController;
            }
        }

        public string strState
        {
            get
            {
                return ViewState["strState"] != null ? ViewState["strState"].ToString() : "";
            }
            set { ViewState["strState"] = value; }
        }

        public string strItemId
        {
            get
            {
                return ViewState["strItemId"] != null ? ViewState["strItemId"].ToString() : "";
            }
            set { ViewState["strItemId"] = value; }
        }

        #endregion

        #region Event Handlers
        protected void Page_Load(Object sender, EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {
                    List<MuaBanXeInfo> carList = this.objCarController.GetCarMuaBanXeList();
                    foreach (MuaBanXeInfo item in carList)
                    {
                        if (!string.IsNullOrEmpty(item.ImageURL))
                        {
                            XmlDocument xdoc = new XmlDocument();
                            xdoc.LoadXml(item.ImageURL);
                            XmlNodeList xnodelist = xdoc.SelectNodes("//root/item");
                            if (xnodelist.Count > 0)
                            {
                                item.ImageItemURL = xnodelist[0].Attributes["value"].Value;
                            }
                        }
                    }
                    this.grdCar.DataSource = carList;
                    this.grdCar.DataBind();

                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        protected void _btnAdd_Click(Object sender, EventArgs e)
        {
            try
            {
                this.txtName.Text = "";
                this.txtOtherInfo.Text = "";
                this.txtPrice.Text = "";

                this._displaySpecification(string.Format(this.xmlSpecification,
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    ""
                    ));

                this.strState = "add";
                this.mvView.SetActiveView(this.viewDetail);
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        protected void _btnSave_Click(Object sender, EventArgs e)
        {
            try
            {
                string strPath = PortalSettings.HomeDirectory + "/productImage/";
                string strURLPath = strPath;
                strPath = Server.MapPath(strPath);
                if (!System.IO.Directory.Exists(strPath))
                {
                    System.IO.Directory.CreateDirectory(strPath);
                }
                bool blnHasImg = false;
                /*
                 <root>
                    <item value='imgURL' />
                    <item value='imgURL' />
                 </root> 
                 */
                if (this.ruUpload.UploadedFiles.Count > 0)
                {
                    foreach (Telerik.Web.UI.UploadedFile item in this.ruUpload.UploadedFiles)
                    {
                        string strPathUpload = strPath + item.FileName;
                        item.SaveAs(strPathUpload);

                        string strURLRealPath = strURLPath + item.FileName;
                        strURLRealPath = strURLRealPath.Replace("/", "\\");

                        this.imgDataTable.Rows.Add(Guid.NewGuid().ToString(), strURLRealPath);
                    }

                    blnHasImg = true;
                }

                this.lvCarListImg.DataSource = imgDataTable;
                this.lvCarListImg.DataBind();

                XmlDocument xdoc = new XmlDocument();
                xdoc.LoadXml("<root />");
                for (int i = 0; i < this.imgDataTable.Rows.Count; i++)
                {
                    XmlNode xnode = xdoc.CreateNode(XmlNodeType.Element, "item", "");
                    XmlAttribute attr = xdoc.CreateAttribute("value");
                    attr.Value = this.imgDataTable.Rows[i]["ImageURL"].ToString();
                    xnode.Attributes.Append(attr);
                    xdoc.DocumentElement.AppendChild(xnode);
                }

                string strContact = string.Format(xmlContact, this.txtContactPerson.Text.Trim(), this.txtContactAddress.Text.Trim(), this.txtContactPhone.Text.Trim());

                this.objCarController.InsertUpdateCar(
                    new MuaBanXeInfo
                    {
                        ModuleId = this.ModuleId,
                        ItemId = this.strState == "add" ? 0 : int.Parse(this.strItemId),
                        CarName = this.txtName.Text.Trim(),
                        CarType = txtCarType.Text.Trim(),
                        Price = this.txtPrice.Text.Trim(),
                        ImageURL = xdoc.OuterXml,
                        OtherInfo = this.txtOtherInfo.Text,
                        CarManufacture = this.txtManufacture.Text,
                        CreatedByUser = this.UserId,
                        ContactInformation = strContact,
                        Specification =
                         string.Format(this.xmlSpecification,
                            this.txtHangCheTao.Text.Trim(),
                            this.txtDoiXe.Text.Trim(),
                            this.txtPhanHangModel.Text.Trim(),
                            this.txtNamSanXuat.Text.Trim(),
                            this.txtXuatXu.Text.Trim(),
                            this.txtTinhTrang.Text.Trim(),
                            this.txtSoKM.Text.Trim(),
                            this.txtDongXe.Text.Trim(),
                            this.txtNgoaiThat.Text.Trim(),
                            this.txtNoiThat.Text.Trim(),
                            this.txtSoCua.Text.Trim(),
                            this.txtSoCho.Text.Trim(),

                            this.txtHeThongNapNhienLieu.Text.Trim(),
                            this.txtNhienLieu.Text.Trim(),

                            this.txtHopSo.Text.Trim(),
                            this.txtDanDong.Text.Trim(),
                            this.txtMucTieuThuNhieLieu.Text.Trim(),

                            this.cbxTuiKhi.Checked ? "1" : "0",
                            this.cbxTuiKhiTruoc.Checked ? "1" : "0",
                            this.cbxTuiKhiSau.Checked ? "1" : "0",
                            this.cbxTuiKhiHaiBen.Checked ? "1" : "0",
                            this.cbxTuiKhiPhiaTren.Checked ? "1" : "0",

                            this.cbxChongBoCungPhanh.Checked ? "1" : "0",
                            this.cbxPhanBoLucPhanhDienTu.Checked ? "1" : "0",
                            this.cbxTroLucPhanhKhanCap.Checked ? "1" : "0",
                            this.cbxTuDongCanBangDienTu.Checked ? "1" : "0",
                            this.cbxDieuKhienHanhTrinh.Checked ? "1" : "0",
                            this.cbxHoTroCanhBaoLui.Checked ? "1" : "0",
                            this.cbxHeThongKiemSoatTruot.Checked ? "1" : "0",

                            this.cbxChotCuaAnToan.Checked ? "1" : "0",
                            this.cbxKhoaCuaTuDong.Checked ? "1" : "0",
                            this.cbxKhoaCuaDienDieuKhienTuXa.Checked ? "1" : "0",
                            this.cbxKhoaDongCo.Checked ? "1" : "0",
                            this.cbxHeThongBaoTromNgoaiVi.Checked ? "1" : "0",

                            this.cbxDenSuongMu.Checked ? "1" : "0",
                            this.cbxDenCanhBaoThatDay.Checked ? "1" : "0",
                            this.cbxDenPhanhPhuThu3.Checked ? "1" : "0",

                            this.cbxThietBiDinhVi.Checked ? "1" : "0",
                            this.cbxCuaSoNoc.Checked ? "1" : "0",
                            this.cbxKinhChinhDien.Checked ? "1" : "0",
                            this.cbxTayLaiTroLuc.Checked ? "1" : "0",
                            this.cbxGhe.Checked ? "1" : "0",
                            this.cbxDieuHoaTruoc.Checked ? "1" : "0",
                            this.cbxDieuHoaSau.Checked ? "1" : "0",
                            this.cbxHoTroXeTuDong.Checked ? "1" : "0",
                            this.cbxXayKinhSau.Checked ? "1" : "0",
                            this.cbxQuatKinhSau.Checked ? "1" : "0",
                            this.cbxKinhMau.Checked ? "1" : "0",
                            this.cbxManHinhlcd.Checked ? "1" : "0",
                            this.cbxThietBiGiaiTri.Checked ? "1" : "0",
                            this.txtThietbikhac.Text.Trim(),

                            this.txtDaiRongCao.Text.Trim(),
                            this.txtDaiCoSo.Text.Trim(),
                            this.txtRongCoSo.Text.Trim(),
                            this.txtTrongLuongKhongTai.Text.Trim(),
                            this.txtDungTichNhienLieu.Text.Trim(),

                            this.txtDongCo.Text.Trim(),
                            this.txtKieuDongCo.Text.Trim(),
                            this.txtDungTichXiLanh.Text.Trim(),

                            this.txtPhanh.Text.Trim(),
                            this.txtGiamXoc.Text.Trim(),
                            this.txtLopXe.Text.Trim(),
                            this.txtVanhMamXe.Text.Trim()
                            )
                    });
                /*
                 <kichthuoctrongluong dairongcao='{51}' daicoso='{52}' rongcoso='{53}' trongluong='{54}' dungtich='{55}' />
                <dongco dongco='{56}' kieudongo='{57}' dungtichxilanh='{58}' />
                <dongco phanh='{59}' giamxoc='{60}' lopxe='{61}' vanhmamxe='{62}' />
                 */
                this.lblResult.Text = "Lưu thành công!";

                if (this.strState == "add")
                {
                    List<MuaBanXeInfo> carList = this.objCarController.GetCarMuaBanXeList();
                    this.grdCar.DataSource = carList;
                    this.grdCar.DataBind();
                    this.mvView.SetActiveView(this.viewListCar);
                }
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        protected void _btnBack_Click(Object sender, EventArgs e)
        {
            try
            {
                List<MuaBanXeInfo> carList = this.objCarController.GetCarMuaBanXeList();
                this.grdCar.DataSource = carList;
                this.grdCar.DataBind();

                this.mvView.SetActiveView(this.viewListCar);
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        public DataTable imgDataTable
        {
            get
            {
                if (ViewState["imgDataTable"] == null)
                {
                    DataTable dt = new DataTable();
                    dt.Columns.Add("ID");
                    dt.Columns.Add("ImageURL");
                    ViewState["imgDataTable"] = dt;
                }
                return ViewState["imgDataTable"] as DataTable;
            }
            set { ViewState["imgDataTable"] = value; }
        }

        protected void _btnEditItem_Click(Object sender, EventArgs e)
        {
            try
            {
                LinkButton btnEditItem = sender as LinkButton;
                this.strItemId = btnEditItem.CommandArgument;
                MuaBanXeInfo objCar = this.objCarController.GetCarMuaBanXe(int.Parse(strItemId));

                this.txtName.Text = objCar.CarName;
                this.txtCarType.Text = objCar.CarType;
                this.txtPrice.Text = objCar.Price;
                this.txtOtherInfo.Text = objCar.OtherInfo;
                this.txtManufacture.Text = objCar.CarManufacture;

                imgDataTable.Rows.Clear();
                if (!string.IsNullOrEmpty(objCar.ImageURL))
                {
                    XmlDocument xDoc = new XmlDocument();
                    xDoc.LoadXml(objCar.ImageURL);
                    /*
                     <root>
                        <item value='imgURL' />
                        <item value='imgURL' />
                     </root> 
                     */


                    XmlNodeList xNodeList = xDoc.SelectNodes("/root/item");
                    int i = 1;
                    foreach (XmlNode item in xNodeList)
                    {
                        imgDataTable.Rows.Add(i, item.Attributes["value"].Value);
                        i++;
                    }
                    this.lvCarListImg.DataSource = imgDataTable;
                    this.lvCarListImg.DataBind();
                }
                else
                {
                    this.lvCarListImg.DataSource = null;
                    this.lvCarListImg.DataBind();
                }

                if (String.IsNullOrEmpty(objCar.ContactInformation))
                {
                    this.txtContactPerson.Text = "";
                    this.txtContactAddress.Text = "";
                    this.txtContactPhone.Text = "";
                }
                else
                {
                    XmlDocument xDocContact = new XmlDocument();
                    xDocContact.LoadXml(objCar.ContactInformation);
                    XmlNode xNodeContact = xDocContact.SelectSingleNode("//root/info");
                    this.txtContactPerson.Text = xNodeContact.Attributes["person"].Value;
                    this.txtContactAddress.Text = xNodeContact.Attributes["address"].Value;
                    this.txtContactPhone.Text = xNodeContact.Attributes["phone"].Value;
                }

                if (String.IsNullOrEmpty(objCar.Specification))
                {
                    this._displaySpecification(this.xmlSpecification);
                }
                else
                {
                    this._displaySpecification(objCar.Specification);
                }

                this.strState = "save";
                this.mvView.SetActiveView(this.viewDetail);
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        protected void _btnDelete_Click(Object sender, EventArgs e)
        {
            try
            {
                LinkButton btnEditItem = sender as LinkButton;
                this.strItemId = btnEditItem.CommandArgument;
                this.objCarController.DeleteCar(int.Parse(strItemId));

                List<MuaBanXeInfo> carList = this.objCarController.GetCarMuaBanXeList();
                this.grdCar.DataSource = carList;
                this.grdCar.DataBind();
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        protected void _btnDeleteImg_Click(Object sender, EventArgs e)
        {
            try
            {
                RadButton btnDeleteImg = sender as RadButton;
                string id = btnDeleteImg.CommandArgument;
                DataRow[] arrDr = this.imgDataTable.Select("ID='" + id + "'");
                this.imgDataTable.Rows.Remove(arrDr[0]);

                this.lvCarListImg.DataSource = imgDataTable;
                this.lvCarListImg.DataBind();
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        #endregion

        #region Other
        private void _displaySpecification(string xmlSpec)
        {
            try
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.LoadXml(xmlSpec);

                XmlNode xthongtincoban = xDoc.SelectSingleNode("//root/thongtincoban");
                //<thongtincoban hangchetao='{0}' doixe='{1}' model='{2}' namsanxuat='{3}' xuatxu='{4}' tinhtrang='{5}' sokm='{6}' dongxe='{7}' ngoaithat='{8}' noithat='{9}' socua='{10}' sochongoi='{11}' />
                this.txtHangCheTao.Text = xthongtincoban.Attributes["hangchetao"].Value;
                this.txtDoiXe.Text = xthongtincoban.Attributes["doixe"].Value;
                this.txtPhanHangModel.Text = xthongtincoban.Attributes["model"].Value;
                this.txtNamSanXuat.Text = xthongtincoban.Attributes["namsanxuat"].Value;
                this.txtXuatXu.Text = xthongtincoban.Attributes["xuatxu"].Value;
                this.txtTinhTrang.Text = xthongtincoban.Attributes["tinhtrang"].Value;
                this.txtSoKM.Text = xthongtincoban.Attributes["sokm"].Value;
                this.txtDongXe.Text = xthongtincoban.Attributes["dongxe"].Value;
                this.txtNgoaiThat.Text = xthongtincoban.Attributes["ngoaithat"].Value;
                this.txtNoiThat.Text = xthongtincoban.Attributes["noithat"].Value;
                this.txtSoCua.Text = xthongtincoban.Attributes["socua"].Value;
                this.txtSoCho.Text = xthongtincoban.Attributes["sochongoi"].Value;

                XmlNode xnhienlieu = xDoc.SelectSingleNode("//root/nhienlieu");
                //<nhienlieu hethongnap='{12}' nhienlieu='{13}' />
                this.txtHeThongNapNhienLieu.Text = xnhienlieu.Attributes["hethongnap"].Value;
                this.txtNhienLieu.Text = xnhienlieu.Attributes["nhienlieu"].Value;

                XmlNode xhopsochuyendong = xDoc.SelectSingleNode("//root/hopsochuyendong");
                //<hopsochuyendong hopso='{14}' dandong='{15}' muctieuthu='{16}' />
                this.txtHopSo.Text = xhopsochuyendong.Attributes["hopso"].Value;
                this.txtDanDong.Text = xhopsochuyendong.Attributes["dandong"].Value;
                this.txtMucTieuThuNhieLieu.Text = xhopsochuyendong.Attributes["muctieuthu"].Value;


                XmlNode xtuikhiantoan = xDoc.SelectSingleNode("//root/tuikhiantoan");
                //tuikhinguoilai='{17}' tuikhitruoc='{18}' tuikhisau='{19}' tuikhihaiben='{20}' tuikhitreophiatren='{21}'/>
                this.cbxTuiKhi.Checked = xtuikhiantoan.Attributes["tuikhinguoilai"].Value == "1" ? true : false;
                this.cbxTuiKhiTruoc.Checked = xtuikhiantoan.Attributes["tuikhitruoc"].Value == "1" ? true : false;
                this.cbxTuiKhiSau.Checked = xtuikhiantoan.Attributes["tuikhisau"].Value == "1" ? true : false;
                this.cbxTuiKhiHaiBen.Checked = xtuikhiantoan.Attributes["tuikhihaiben"].Value == "1" ? true : false;
                this.cbxTuiKhiPhiaTren.Checked = xtuikhiantoan.Attributes["tuikhitreophiatren"].Value == "1" ? true : false;

                XmlNode xphanhdieukhien = xDoc.SelectSingleNode("//root/phanhdieukhien");
                //chongbocungphanh='{22}' phanbolucphanhdientu='{23}' trolucphanhkhancap='{24}' tudongcanbangdientu='{25}' dieukhienhanhtrinh='{26}' hotrobaolui='{27}' hethongkiemsoattruot='{28}'/>
                this.cbxChongBoCungPhanh.Checked = xphanhdieukhien.Attributes["chongbocungphanh"].Value == "1" ? true : false;
                this.cbxPhanBoLucPhanhDienTu.Checked = xphanhdieukhien.Attributes["phanbolucphanhdientu"].Value == "1" ? true : false;
                this.cbxTroLucPhanhKhanCap.Checked = xphanhdieukhien.Attributes["trolucphanhkhancap"].Value == "1" ? true : false;
                this.cbxTuDongCanBangDienTu.Checked = xphanhdieukhien.Attributes["tudongcanbangdientu"].Value == "1" ? true : false;
                this.cbxDieuKhienHanhTrinh.Checked = xphanhdieukhien.Attributes["dieukhienhanhtrinh"].Value == "1" ? true : false;
                this.cbxHoTroCanhBaoLui.Checked = xphanhdieukhien.Attributes["hotrobaolui"].Value == "1" ? true : false;
                this.cbxHeThongKiemSoatTruot.Checked = xphanhdieukhien.Attributes["hethongkiemsoattruot"].Value == "1" ? true : false;

                XmlNode xkhoachongtrom = xDoc.SelectSingleNode("//root/khoachongtrom");
                //chotcuaantoan='{29}' khoacuatudong='{30}' khoacuadieukhientuxa='{31}' khoadongco='{32}' hethongbaotromngoaivi='{33}'/>
                this.cbxChotCuaAnToan.Checked = xkhoachongtrom.Attributes["chotcuaantoan"].Value == "1" ? true : false;
                this.cbxKhoaCuaTuDong.Checked = xkhoachongtrom.Attributes["khoacuatudong"].Value == "1" ? true : false;
                this.cbxKhoaCuaDienDieuKhienTuXa.Checked = xkhoachongtrom.Attributes["khoacuadieukhientuxa"].Value == "1" ? true : false;
                this.cbxKhoaDongCo.Checked = xkhoachongtrom.Attributes["khoadongco"].Value == "1" ? true : false;
                this.cbxHeThongBaoTromNgoaiVi.Checked = xkhoachongtrom.Attributes["hethongbaotromngoaivi"].Value == "1" ? true : false;

                XmlNode xthongsokhac = xDoc.SelectSingleNode("//root/thongsokhac");
                //densuongmu='{34}' dencanhbaotatdayantoan='{35}' denphanhphuthu3lapcao='{36}'/>
                this.cbxDenSuongMu.Checked = xthongsokhac.Attributes["densuongmu"].Value == "1" ? true : false;
                this.cbxDenCanhBaoThatDay.Checked = xthongsokhac.Attributes["dencanhbaotatdayantoan"].Value == "1" ? true : false;
                this.cbxDenPhanhPhuThu3.Checked = xthongsokhac.Attributes["denphanhphuthu3lapcao"].Value == "1" ? true : false;

                XmlNode xtiennghi = xDoc.SelectSingleNode("//root/tiennghi");
                //thietbidinhvi='{37}' cuasonoc='{38}' kinhchinhdien='{39}' taylaitroluc='{40}' ghe='{41}' 
                //dieuhoatruoc='{42}' dieuhoasau='{43}' hotroxetudong='{44}' xaykinhsau='{45}' quatkinhsau='{46}' kinhmau='{47}' manhinhlcd='{48}' thietbigiaitri='{49}' thietbikhac='{50}'/>
                this.cbxThietBiDinhVi.Checked = xtiennghi.Attributes["thietbidinhvi"].Value == "1" ? true : false;
                this.cbxCuaSoNoc.Checked = xtiennghi.Attributes["cuasonoc"].Value == "1" ? true : false;
                this.cbxKinhChinhDien.Checked = xtiennghi.Attributes["kinhchinhdien"].Value == "1" ? true : false;
                this.cbxTayLaiTroLuc.Checked = xtiennghi.Attributes["taylaitroluc"].Value == "1" ? true : false;
                this.cbxGhe.Checked = xtiennghi.Attributes["ghe"].Value == "1" ? true : false;
                this.cbxDieuHoaTruoc.Checked = xtiennghi.Attributes["dieuhoatruoc"].Value == "1" ? true : false;
                this.cbxDieuHoaSau.Checked = xtiennghi.Attributes["dieuhoasau"].Value == "1" ? true : false;
                this.cbxHoTroXeTuDong.Checked = xtiennghi.Attributes["hotroxetudong"].Value == "1" ? true : false;
                this.cbxXayKinhSau.Checked = xtiennghi.Attributes["xaykinhsau"].Value == "1" ? true : false;
                this.cbxQuatKinhSau.Checked = xtiennghi.Attributes["quatkinhsau"].Value == "1" ? true : false;
                this.cbxKinhMau.Checked = xtiennghi.Attributes["kinhmau"].Value == "1" ? true : false;
                this.cbxManHinhlcd.Checked = xtiennghi.Attributes["manhinhlcd"].Value == "1" ? true : false;
                this.cbxThietBiGiaiTri.Checked = xtiennghi.Attributes["thietbigiaitri"].Value == "1" ? true : false;

                /*
                 <kichthuoctrongluong dairongcao='{51}' daicoso='{52}' rongcoso='{53}' trongluong='{54}' dungtich='{55}' />
                 */
                XmlNode xkichthuoctrongluong = xDoc.SelectSingleNode("//root/kichthuoctrongluong");
                if (xkichthuoctrongluong != null)
                {
                    this.txtDaiRongCao.Text = xkichthuoctrongluong.Attributes["dairongcao"].Value;
                    this.txtDaiCoSo.Text = xkichthuoctrongluong.Attributes["daicoso"].Value;
                    this.txtRongCoSo.Text = xkichthuoctrongluong.Attributes["rongcoso"].Value;
                    this.txtTrongLuongKhongTai.Text = xkichthuoctrongluong.Attributes["trongluong"].Value;
                    this.txtDungTichNhienLieu.Text = xkichthuoctrongluong.Attributes["dungtich"].Value;
                }
                /*
                <dongco dongco='{56}' kieudongco='{57}' dungtichxilanh='{58}' />
                */
                XmlNode xdongco = xDoc.SelectSingleNode("//root/dongco");
                if (xdongco != null)
                {
                    this.txtDongCo.Text = xdongco.Attributes["dongco"].Value;
                    this.txtKieuDongCo.Text = xdongco.Attributes["kieudongco"].Value;
                    this.txtDungTichXiLanh.Text = xdongco.Attributes["dungtichxilanh"].Value;
                }
                /*
                <phanhxoclop phanh='{59}' giamxoc='{60}' lopxe='{61}' vanhmamxe='{62}' />
               */
                XmlNode xphanhxoclop = xDoc.SelectSingleNode("//root/phanhxoclop");
                if (xphanhxoclop != null)
                {
                    this.txtPhanh.Text = xphanhxoclop.Attributes["phanh"].Value;
                    this.txtGiamXoc.Text = xphanhxoclop.Attributes["giamxoc"].Value;
                    this.txtLopXe.Text = xphanhxoclop.Attributes["lopxe"].Value;
                    this.txtVanhMamXe.Text = xphanhxoclop.Attributes["vanhmamxe"].Value;
                }
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        #endregion
    }
}

